<?php
    $h = "7";// Hour for time zone goes here e.g. +7 or -4, just remove the + or -
    $hm = $h * 60; 
    $ms = $hm * 60;
?>

<table class="table-content" cellspacing="0" cellpadding="0" >
    <col width="50px" />
    <col width="550px" />
    <col width="80px" />
    <col width="50px" />
    <col width="50px" />
    <tr class="table-header">
        <!--<th class="center" width="20px;">
        <input type="checkbox" name="test" onchange="checkAll()" id="checkAll"/>
        </th>-->
        <th>user_id</th>
        <th>Comment</th>
        <th>Thời gian</th>
        <th>Number of like</th>
        <th>Number of dislike</th>
    </tr>
    <?php foreach($this->commentList as $key=>$value){?>
        <tr>
            <td class="container"><div><?php echo $value->user_id ?></div></td>
            <td class="container"><div><?php echo $value->comment ?></div></td>
            <td class="container"><div><?php echo gmdate('d-m-Y H:i', ($value->comment_time +$ms) ); ?></div></td>
            <td class="container"><div><?php echo $value->no_of_like ?></div></td>
            <td class="container"><div><?php echo $value->no_of_dislike ?></div></td>
        </tr>
    <?php } ?>
</table>
<div class="pagging">
    <a class="pagging-first" id="pagging-first" href="#" onclick="loadTable(1); return false;"></a>
    <a class="pagging-pre" id="pagging-pre" href="#"></a>
    <input class="pagging-seach" id="pagging-seach" value="<?php echo $this->page;?>"/><div class="pagging-info">of <?php echo $this->pageNumber; ?></div>
    <a class="pagging-next" id="pagging-next" href="#"></a>
    <a class="pagging-last" id="pagging-last" href="#" onclick="loadTable(<?php echo $this->pageNumber;?>); return false;" ></a>
</div>

<script>
    
    function loadMerchant(url,id){
        url = url + "?id="+id;
        window.location.replace(url);   
    }
    
    function loadTable(page){
        url = '/place/place-comment/load-place-comment' + "?page="+page+"&place_id=<?php echo $this->placeId ?>";
        $("#pagging-seach").val(page);
        $("#table-place-comment").load(url);
    }

    
    $(document).ready(function(){
        $("#pagging-pre").click(function(e){
            page = parseInt($("#pagging-seach").val());
            prev_page = page - 1;
            if(prev_page < 1){
                return false;
            }else{
                $("#pagging-seach").val(prev_page);
                
                if(prev_page > 0){
                    //$("#merchant-table").load('/place/merchant-place/load-place' + "?page="+prev_page);
                    url = '/place/place-comment/load-place-comment' + "?page="+prev_page+"&place_id=<?php echo $this->placeId ?>";
                    $("#table-place-comment").load(url);
                    return false;
                }
                
            }
        });
        
        $("#pagging-next").click(function(e){
            page = parseInt($("#pagging-seach").val());
            next_page = page + 1;
            if(next_page > <?php echo $this->pageNumber?>){
                return false;
            }else{
                
                $("#pagging-seach").val(next_page);
                //$("#merchant-table").load('/place/merchant-place/load-place' + "?page="+next_page);
                url = '/place/place-comment/load-place-comment' + "?page="+next_page+"&place_id=<?php echo $this->placeId ?>";
                $("#table-place-comment").load(url);
                return false;
            }
        });
        
        $("#pagging-seach").keyup(function(event){
            if(event.keyCode == 13){
                page = $("#pagging-seach").val();
                if(page > 0 && page <= <?php echo $this->pageNumber?>){
                    $("#pagging-seach").val(page);
                    //$("#merchant-table").load('/place/merchant-place/load-place' + "?page="+page);
                    url = '/place/place-comment/load-place-comment' + "?page="+page+"&place_id=<?php echo $this->placeId ?>";
                    $("#table-place-comment").load(url);
                }else if(page <= 0){
                    //$("#merchant-table").load('/place/merchant-place/load-place');
                    url = '/place/place-comment/load-place-comment' + "?page="+1+"&place_id=<?php echo $this->placeId ?>";
                    $("#table-place-comment").load('/place/merchant-place/load-place');
                    $("#pagging-seach").val(1);
                }else if(page > <?php echo $this->pageNumber?>){
                    $("#pagging-seach").val(<?php echo $this->pageNumber?>);
                    url = '/place/place-comment/load-place-comment' + "?page="+<?php echo $this->pageNumber?>+"&place_id=<?php echo $this->placeId ?>";
                    $("#table-place-comment").load(url);
                    //$("#merchant-table").load('/place/merchant-place/load-place' + "?page="+<?php echo $this->pageNumber?>);
                }
            }
        });
    });
</script>